import java.util.ArrayList;
import java.util.List;

public class Inventory {
    Product product;
    Commodity commodity;
    ElectronicDevice electronicDevice;
    Food food;
    List<Product> productList = new ArrayList<>();

    public Inventory() {
        // this.productList = productList;
        //Add your products here(Commodity,Food and E-device)
        //e.g. Food apple = new Food()
        // Electronic iphone12 = new Electronic()
        //Commodity brush = new Commodity()
        //Push them to the list here
        //e.g. productList.add(apple) etc......
        ElectronicDevice phone1 = new ElectronicDevice("iPhone12pro", 100, 8400.00, "null", "InStock", "E", "Blue", 6.1, 128);
        ElectronicDevice phone2 = new ElectronicDevice("iPhone12", 100, 6299.00, "null", "InStock", "E", "White", 6.1, 64);
        ElectronicDevice phone3 = new ElectronicDevice("iPhone12mini", 100, 5499.00, "null", "InStock", "E", "White", 5.4, 64);
        ElectronicDevice pad1 = new ElectronicDevice("iPadpro", 100, 7899.00, "null", "InStock", "E", "Silver", 12.9, 128);
        ElectronicDevice pad2 = new ElectronicDevice("iPadair", 100, 4799.00, "null", "InStock", "E", "Silver", 10.9, 64);
        ElectronicDevice pad3 = new ElectronicDevice("iPad", 100, 2499.00, "null", "InStock", "E", "Silver", 10.2, 32);
        Commodity mop = new Commodity("mop", 15, 233.9, "", "In Stock", "C", "Karcher", "black", "living room");
        Commodity shampoo = new Commodity("shampoo", 100, 88.8, "", "In Stock", "C", "Unilever", "purple", "bathroom");
        Commodity hairdryer = new Commodity("hairdryer", 5, 2399.8, "popular", "In Stock", "C", "Dyson", "red", "bathroom");
        Commodity hanger = new Commodity("hanger", 666, 15.9, "", "Sold Out", "C", "Ikea", "black", "balcony");
        Commodity washingliquid = new Commodity("washingliquid", 150, 29.9, "", "In Stock", "C", "Areil", "yellow", "kitchen");

        Food fruit = new Food("fruit", 20, 20.0, "s", "Instock", "F", "Solid", 5, true);
        Food bakery = new Food("bakery", 10, 10.0, "s", "Instock", "F", "Solid", 2, true);
        Food snack = new Food("snack", 80, 20.0, "s", "Instock", "F", "Solid", 365, false);
        Food alcohol = new Food("alcohol", 20, 200.0, "s", "Instock", "F", "liquid", 700, false);

        this.productList.add(phone1);
        this.productList.add(pad1);
        this.productList.add(mop);
        this.productList.add(shampoo);
        this.productList.add(fruit);
        this.productList.add(bakery);
    }

    public List<Product> findProdList(String opt) {
        // 放到 inventory class
        List<Product> resultList = new ArrayList<>();
        for (int i = 0; i < this.productList.size(); i++) {
            if (productList.get(i).Category.compareTo(opt) == 0) {
                resultList.add(productList.get(i));
            }
        }
        return resultList;
    }

    public void showOptProduct(String opt) {
        List<Product> resultList = findProdList(opt);
        for (int i = 0; i < resultList.size(); i++) {
            System.out.println(resultList.get(i).toString());
        }
    }

    public Boolean checkValid_item_num(String name, int num) { // move to inventory
        // 放到 inventory class
        for (int i = 0; i < productList.size(); i++) {
            Product item = productList.get(i);
            if (name.compareTo(item.getName()) == 0 && num <= item.getQuantity()) {
                return true;
            }
        }
        return false;
    }

    // public void showAllProduct() {
    //     for (int i = 0; i < productList.size(); i++) {
    //         System.out.println(productList.get(i).toString());
    //     }
    // }

    // public void showElectronicDevice() {
    //     for (int i = 0; i < productList.size(); i++) {
    //         if (productList.get(i).getCategory().compareTo("E") == 0) {
    //             System.out.println(productList.get(i).toString());
    //         }
    //     }
    // }

    // public void showCommodity() {
    //     for (int i = 0; i < productList.size(); i++) {
    //         System.out.println(productList.toString());
    //     }
    // }

    // public void showFood() {
    //     for (int i = 0; i < productList.size(); i++) {
    //         System.out.println(productList.toString());
    //     }
    // }
}
